<?php 
class partyClassAction extends Action
{
	public function defaultAction()
	{
		
	}
	
	public function dataAction()
	{
		$limit= (int)$this->get('limit','1');
		$sort = $this->get('sort');
		$dir  = $this->get('dir');
		$order= '`zxdt` desc';
		if($sort && $dir)$order= '`'.$sort.'` '.$dir.'';
		$barr = m('party')->getlimit('1=1', (int)$this->get('page','1'),'*',$order, $limit);
		$rows  = $barr['rows'];
		
		$ageobj = m('agent');
		$urobj  = m('users');
		foreach($rows as $k=>$rs){
			$agrs = $ageobj->getXinxi($rs['agentid']);
			$rows[$k]['agentid'] = '<img src="'.$agrs['picurl'].'" align="absmiddle" height="16" width="16" style="border-radius:50%"> '.$agrs['name'];
			$uidss = '';
			if($rs['uid']>0){
				$kfrs  = $urobj->geturs($rs['uid']);
				$uidss = '<img src="'.$kfrs['face'].'" align="absmiddle" height="16" width="16" style="border-radius:50%"> '.$kfrs['name'];
				if(!isempt($kfrs['ranking']))$uidss.='<font color="gray">('.$kfrs['ranking'].')</font>';
			}
			$rows[$k]['uid'] = $uidss;
		}
		
		$total = count($rows);
		$barr = array(
			'rows' => $rows,
			'totalCount'=> $barr['count'],
			'success' => true,
		);
		return $barr;
	}
	
	public function messAction()
	{
		
	}
	
	public function messdataAction()
	{
		$limit= (int)$this->get('limit','1');
		$zxid = (int)$this->get('zxid','0');
		$sort = $this->get('sort');
		$dir  = $this->get('dir');
		$order= '`id` desc';
		if($sort && $dir)$order= '`'.$sort.'` '.$dir.'';
		$where  = '`type`=0';
		
		if($zxid>0)$where = '`type`=0 and ((`slx`=0 and `sendid`='.$zxid.') or (`slx`=1 and `receid`='.$zxid.') )';
		
		$barr   = m('mess')->getlimit($where, (int)$this->get('page','1'),'*',$order, $limit);
		$rows   = $barr['rows'];
		$urobj  = m('users');
		$probj  = m('party');
		$fobj  = m('file');
		$typea  = array('咨询','人员');
		foreach($rows as $k=>$rs){
			$uidss = '';
			$recss = '';
			if($rs['slx']==1){
				$kfrs  = $urobj->geturs($rs['sendid']);
				$uidss = '<img src="'.$kfrs['face'].'" align="absmiddle" height="16" width="16" style="border-radius:50%"> '.$kfrs['name'];
				if(!isempt($kfrs['ranking']))$uidss.='<font color="gray">('.$kfrs['ranking'].')</font>';
				
				if($rs['type']==0){
					$kfrs  = $probj->getInfo($rs['receid']);
					$recss = $kfrs['name'];
				}
			}
			if($rs['slx']==0){
				$kfrs  = $probj->getInfo($rs['sendid']);
				$uidss = $kfrs['name'];
			}
			
			if($rs['type']==1 || $rs['slx']==0){
				$kfrs  = $urobj->geturs($rs['receid']);
				$recss = '<img src="'.$kfrs['face'].'" align="absmiddle" height="16" width="16" style="border-radius:50%"> '.$kfrs['name'];
				if(!isempt($kfrs['ranking']))$recss.='<font color="gray">('.$kfrs['ranking'].')</font>';
			}
			$filestr = '';
			if($rs['fileid']>0){
				$frs = $fobj->getXinxi($rs['fileid']);
				if($frs && file_exists($frs['filepath'])){
					$filestr = '<a class="zhu" onclick="js.fileopt('.$rs['fileid'].',0)" href="javascript:;">预览</a> <a href="javascript:;" class="zhu" onclick="js.fileopt('.$rs['fileid'].',1)">下载</a>';
				}
			}
			
			$rows[$k]['sendid'] = $uidss;
			$rows[$k]['receid'] = $recss;
			$rows[$k]['fileid'] = $filestr;
			
			$rows[$k]['type'] 	= $typea[$rs['type']];
		}
		
		$total = count($rows);
		$barr = array(
			'rows' => $rows,
			'totalCount'=> $barr['count'],
			'success' => true,
		);
		return $barr;
	}
}